package per.dg.tools;

import android.content.Context;
import android.media.AudioManager;

public class VolumeManager {

    private static VolumeManager INSTANCE;

    public static VolumeManager getInstance(Context mContext){
        if(INSTANCE == null){
            synchronized (VolumeManager.class){
                if(INSTANCE == null){
                    INSTANCE = new VolumeManager(mContext);
                }
            }
        }
        return INSTANCE;
    }

    private AudioManager audioManager;

    private VolumeManager(Context mContext){
        audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
    }

    /**
     * 获取通话音量
     * @return
     */
    public int getCallVolume(){
        return audioManager.getStreamVolume(AudioManager.STREAM_VOICE_CALL);
    }

    /**
     * 设置通话音量
     */
    public void setCallVolume(int volume){
       audioManager.setStreamVolume(AudioManager.STREAM_VOICE_CALL, volume, AudioManager.FLAG_PLAY_SOUND);
    }

    /**
     * 获取通话最大音量
     * @return
     */
    public int getCallMaxVolume(){
        return audioManager.getStreamMaxVolume(AudioManager.STREAM_VOICE_CALL);
    }

    /**
     * 获取系统音量
     * @return
     */
    public int getSystemVolume(){
        return audioManager.getStreamVolume(AudioManager.STREAM_SYSTEM);
    }

    /**
     * 设置系统音量
     */
    public void setSystemVolume(int volume){
        audioManager.setStreamVolume(AudioManager.STREAM_SYSTEM, volume, AudioManager.FLAG_PLAY_SOUND);
    }

    /**
     * 获取系统最大音量
     * @return
     */
    public int getSystemMaxVolume(){
        return audioManager.getStreamMaxVolume(AudioManager.STREAM_SYSTEM);
    }

    /**
     * 获取铃声音量
     * @return
     */
    public int getRingVolume(){
        return audioManager.getStreamVolume(AudioManager.STREAM_RING);
    }

    /**
     * 设置铃声音量
     */
    public void setRingVolume(int volume){
        audioManager.setStreamVolume(AudioManager.STREAM_RING, volume, AudioManager.FLAG_PLAY_SOUND);
    }

    /**
     * 获取铃声最大音量
     * @return
     */
    public int getRingmMaxVolume(){
        return audioManager.getStreamMaxVolume(AudioManager.STREAM_RING);
    }

    /**
     * 获取音乐音量
     * @return
     */
    public int getMusicVolume(){
        return audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
    }

    /**
     * 设置音乐音量
     */
    public void setMusicVolume(int volume){
        audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, volume, AudioManager.FLAG_PLAY_SOUND);
    }

    /**
     * 获取音乐最大音量
     * @return
     */
    public int getMusicMaxVolume(){
        return audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
    }

    /**
     * 获取提示音音量
     * @return
     */
    public int getAlarmVolume(){
        return audioManager.getStreamVolume(AudioManager.STREAM_ALARM);
    }

    /**
     * 设置提示音音量
     */
    public void setAlarmVolume(int volume){
        audioManager.setStreamVolume(AudioManager.STREAM_ALARM, volume, AudioManager.FLAG_PLAY_SOUND);
    }

    /**
     * 获取提示音最大音量
     * @return
     */
    public int getAlarmMaxVolume(){
        return audioManager.getStreamMaxVolume(AudioManager.STREAM_ALARM);
    }

}
